package com.spring.ioc.controller;

import com.spring.ioc.config.UserConfig;
import com.spring.ioc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class HelloController {
    //属性注入
//    @Autowired
//    private UserService userService;

    //构造方法注入
    private UserService userService;
    private UserConfig userConfig;
    //有无参就调用无参的构造函数
//    public HelloController() {
//    }

    public HelloController(UserService userService) {
        this.userService = userService;
    }

    //这个@Autowired是指定构造函数
    @Autowired
    public HelloController(UserService userService, UserConfig userConfig) {
        this.userService = userService;
        this.userConfig = userConfig;
    }

    //setter 方法注入

//    private UserService userService;
//    private UserConfig userConfig;
//
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }
//    @Autowired
//    public void setUserConfig(UserConfig userConfig) {
//        this.userConfig = userConfig;
//    }

    public void print() {
        System.out.println("do Controller");
        userService.print();
        userConfig.print();
    }
}
